//package com.js.mvpdemo.base;
//
//import android.os.Bundle;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//
//import androidx.annotation.Nullable;
//import androidx.recyclerview.widget.GridLayoutManager;
//import androidx.recyclerview.widget.RecyclerView;
//
//import com.js.fzxj.ui.first.upload.GlideEngine;
//import com.js.fzxj.ui.first.upload.GridImageAdapter;
//import com.js.lib_common.base.BaseFragment;
//import com.js.lib_common.base.BasePresenter;
//import com.luck.picture.lib.PictureSelector;
//import com.luck.picture.lib.config.PictureConfig;
//import com.luck.picture.lib.config.PictureMimeType;
//import com.luck.picture.lib.entity.LocalMedia;
//import com.luck.picture.lib.listener.OnResultCallbackListener;
//
//import java.lang.ref.WeakReference;
//import java.util.List;
//
//import io.reactivex.annotations.NonNull;
//
//
//public abstract class BaseUploadFragment<P extends BasePresenter> extends BaseFragment {
//    protected P mvpPresenter;
//    private GridImageAdapter mAdapter;
//
//    @Nullable
//    @Override
//    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        mvpPresenter = createPresenter();
//        return super.onCreateView(inflater, container, savedInstanceState);
//
//    }
//
//    protected abstract P createPresenter();
//
//
//    @Override
//    public void onDestroyView() {
//        if (mvpPresenter != null) {
//            mvpPresenter.detachView();
//        }
//
//        super.onDestroyView();
//    }
//
//
//    public void showLoading() {
//        showLoadingDialog();
//    }
//
//    public void hideLoading() {
//        dismissLoadingDialog();
//    }
//
//
//    public void initUpload(RecyclerView rcyList) {
//        GridLayoutManager mGridLayoutManager = new GridLayoutManager(_mActivity, 5);
//        //方向，水平
//        mGridLayoutManager.setOrientation(RecyclerView.VERTICAL);
//        //给RecyclerView设置布局管理器
//        rcyList.setLayoutManager(mGridLayoutManager);
//        rcyList.setHasFixedSize(true);
//        rcyList.setLayoutManager(mGridLayoutManager);
//        mAdapter = new GridImageAdapter(getContext(), () -> PictureSelector.create(_mActivity)
//                .openGallery(PictureMimeType.ofImage())
//                .previewImage(false)//是否预览图片
//                .selectionMode(PictureConfig.MULTIPLE)//单选or多选 PictureConfig.SINGLE PictureConfig.MULTIPLE
//                .loadImageEngine(GlideEngine.createGlideEngine())
//                .isSingleDirectReturn(true)//PictureConfig.SINGLE模式下是否直接返回
//                .isWeChatStyle(true)//开启R.style.picture_WeChat_style样式
//                .maxSelectNum(4)
//                .forResult(new MyResultCallback(mAdapter)));
//
//        mAdapter.setSelectMax(5);
//        rcyList.setAdapter(mAdapter);
//        mAdapter.setOnItemClickListener((v, position) -> {
//            List<LocalMedia> selectList = mAdapter.getData();
//            if (selectList.size() > 0) {
//                LocalMedia media = selectList.get(position);
//                String mimeType = media.getMimeType();
//                int mediaType = PictureMimeType.getMimeType(mimeType);
//                switch (mediaType) {
//                    case PictureConfig.TYPE_VIDEO:
//                        // 预览视频
//                        PictureSelector.create(_mActivity).externalPictureVideo(media.getPath());
//                        break;
//                    case PictureConfig.TYPE_AUDIO:
//                        // 预览音频
//                        PictureSelector.create(_mActivity).externalPictureAudio(media.getPath());
//                        break;
//                    default:
//                        // 预览图片 可自定长按保存路径
//                        PictureSelector.create(_mActivity)
//                                //.themeStyle(themeId) // xml设置主题
//                                .setPictureStyle(null)// 动态自定义相册主题
//                                //.setPictureWindowAnimationStyle(animationStyle)// 自定义页面启动动画
//                                .isNotPreviewDownload(true)// 预览图片长按是否可以下载
//                                .imageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
//                                .openExternalPreview(position, selectList);
//                        break;
//                }
//            }
//        });
//    }
//
//
//    public  List<LocalMedia>  getUploadList(){
//       return mAdapter.getData();
//    }
//
//
//
//    /**
//     * 返回结果回调
//     */
//    private  class MyResultCallback implements OnResultCallbackListener<LocalMedia> {
//        private WeakReference<GridImageAdapter> mAdapterWeakReference;
//
//        public MyResultCallback(GridImageAdapter adapter) {
//            super();
//            this.mAdapterWeakReference = new WeakReference<>(adapter);
//        }
//
//        @Override
//        public void onResult(List<LocalMedia> result) {
//            if (mAdapterWeakReference.get() != null) {
//                mAdapterWeakReference.get().setList(result);
//                mAdapterWeakReference.get().notifyDataSetChanged();
//            }
//        }
//
//        @Override
//        public void onCancel() {
//
//
//        }
//    }
//
//}
